package com.surrealbananapeel.battleship;

/**
 * This class holds the fleet information. You cannot instantiate it 
 * just use the static methods to get the ships you need.
 * 
 * @author Emmett Little and Alberto Saavedra
 */
public class Fleet
{
    private static Ship[] fleet;
    
    static
    {
        fleet = new Ship[5];
        fleet[4] = new Ship("FF:0,0,0;1,0,0;2,0,0");
        fleet[3] = new Ship("SSK:0,0,0;1,0,0;2,0,0;3,0,0;4,0,0");
        fleet[2] = new Ship("DDH:1,0,0;0,1,0;1,1,0;2,1,0;1,2,0");
        fleet[1] = new Ship("BB:0,0,0;1,0,0;2,0,0;0,1,0;2,1,0;0,2,0;1,2,0;2,2,0");
        fleet[0] = new Ship("CVL:2,2,0;2,2,1;2,0,2;2,1,2;0,2,2;1,2,2;2,2,2;3,2,2;4,2,2;2,3,2;2,4,2;2,2,3;2,2,4");
    }
    
    /**
     * Prevent instantiation.
     */
    private Fleet()
    {
    }
    
    /**
     * Get the ship which has the supplied name. If the ship doesn't exist 
     * then null is returned.
     * 
     * @param name The name of the ship to get
     * @return A ship object that is your supplied name, or null
     */
    public static Ship getShip(String name)
    {
        for (int i = 0; i < fleet.length; i++)
        {
            if (fleet[i].getName().equals(name))
            {
                return new Ship(fleet[i]);
            }
        }
        return null;
    }
    
    /**
     * Get all the ships the fleet has.
     * 
     * @return All the ships
     */
    public static Ship[] getShips()
    {
        Ship[] theShips = new Ship[fleet.length];
        for (int i = 0; i < theShips.length; i++)
        {
            theShips[i] = new Ship(fleet[i]);
        }
        return theShips;
    }
}
